package message.visitor.tests;

import junit.framework.Assert;
import message.types.data.AddDataRequest;
import message.types.data.GetLastDataAnswer;
import message.types.message.RejectedRequest;
import message.types.none.GetAllDatasRequest;
import message.types.none.GetLastDataRequest;
import message.types.none.NewDataNotification;
import message.types.stalker.RegisterRequest;
import message.types.unique.EmptyMessage;
import message.types.unique.RoomInvitation;

import org.junit.Test;

import stalker.Stalker;
import stalker.room.PrivatePersistentRoom;
import stalker.room.Room;
import stalker.tester.TesterStalker;
import data.Data;
import data.content.Content;
import data.content.ContentSentence;
import data.datas.CompleteHistoryDatas;
import data.datas.Datas;


public class RoomMessageVisitorTest {
  
  @Test
  public void test01() throws InterruptedException {
    TesterStalker tester = new TesterStalker();
    Room test_room = PrivatePersistentRoom.create("Forest");
    // User lucifer = User.createUser("Lucifer");
    Content test_content = new ContentSentence("Love");
    Data test_data = new Data(tester, test_content);
    Datas test_datas = new CompleteHistoryDatas();
    test_datas.insertData(test_data);
    test_room.acceptMessage(
        new EmptyMessage()
        );
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new RegisterRequest(tester, test_room, tester)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            test_room, 
            tester, 
            new RegisterRequest(tester, test_room, tester)
            )
        ));
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new GetLastDataRequest(tester, test_room)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            test_room, 
            tester, 
            new GetLastDataRequest(tester, test_room)
            )
        ));
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new AddDataRequest(tester, test_room, test_content)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            test_room, 
            tester, 
            new AddDataRequest(tester, test_room, test_content)
            )
        ));
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new GetAllDatasRequest(tester, test_room)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            test_room, 
            tester, 
            new GetAllDatasRequest(tester, test_room)
            )
        ));
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new RegisterRequest(Stalker.ROOM_MANAGER_STALKER, test_room, tester)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RoomInvitation(test_room, tester, test_room, Stalker.ROOM_MANAGER_STALKER)
    ));
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new AddDataRequest(tester, test_room, test_content)
        );
    
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new NewDataNotification(test_room, tester)
    ));
    Thread.sleep(25);
    test_room.acceptMessage(
        new GetLastDataRequest(tester, test_room)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new GetLastDataAnswer(test_room, tester, test_data)
    ));
    Thread.sleep(25);
    test_room.acceptMessage(
        new GetAllDatasRequest(tester, test_room)
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessageAllDatasAnswer());
    
    Thread.sleep(25);
    test_room.acceptMessage(
        new RejectedRequest(test_room, tester, new EmptyMessage())
        );
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new RejectedRequest(test_room, tester, new EmptyMessage())));
    
    
  }
  
}
